{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "05a8bd12-143e-492d-9ea8-2d7fe2e5f91d",
   "metadata": {},
   "source": [
    "# 第九节、数学和统计方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d4eda5d-fe99-49c0-9caf-b26cfe84e985",
   "metadata": {},
   "source": [
    "pandas 对象拥有一组常用的数学和统计方法。它们属于汇总统计，对Series汇总计算获取mean、max值或者对DataFrame行列汇总计算返回一个Series"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf661c1d-0c23-4ef1-8a9c-47f78dac4b77",
   "metadata": {},
   "source": [
    "## 简单统计指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "aadafc63-4a72-45a9-a430-6f597778e927",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8f598ba3-50dc-4f2b-affc-3df952aa53e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>28</td>\n",
       "      <td>93</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>91</td>\n",
       "      <td>51</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>31</td>\n",
       "      <td>21</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>50</td>\n",
       "      <td>62</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>30</td>\n",
       "      <td>99</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>2</td>\n",
       "      <td>86</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>87</td>\n",
       "      <td>59</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>54</td>\n",
       "      <td>12</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>20</td>\n",
       "      <td>4</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>18</td>\n",
       "      <td>23</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>96</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>11</td>\n",
       "      <td>19</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>28</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>65</td>\n",
       "      <td>87</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>14</td>\n",
       "      <td>82</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>45</td>\n",
       "      <td>32</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>6</td>\n",
       "      <td>31</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>40</td>\n",
       "      <td>51</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>11</td>\n",
       "      <td>63</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>72</td>\n",
       "      <td>9</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      28          93     90\n",
       "B      91          51     93\n",
       "C      31          21     93\n",
       "D      50          62     10\n",
       "E      30          99     24\n",
       "F       2          86     88\n",
       "H      87          59     65\n",
       "I      54          12     68\n",
       "J      20           4     82\n",
       "K      18          23     63\n",
       "L      96           9      7\n",
       "M      11          19     43\n",
       "N      28          20      2\n",
       "O      65          87      3\n",
       "P      14          82     98\n",
       "Q      45          32     36\n",
       "R       6          31     81\n",
       "S      40          51     70\n",
       "T      11          63     84\n",
       "U      72           9     74"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(\n",
    "    data=np.random.randint(0,100, size=(20,3)),\n",
    "    index=list('ABCDEFHIJKLMNOPQRSTU'),\n",
    "    columns=['Python','Tensorflow','Keras']\n",
    ")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1b49486a-327c-43bf-b47c-40226c4d14ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        20\n",
       "Tensorflow    20\n",
       "Keras         20\n",
       "dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 统计非空的元素\n",
    "df.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "60ce8719-4a7a-4832-94b3-2be34f9b5fab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        96\n",
       "Tensorflow    99\n",
       "Keras         98\n",
       "dtype: int32"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 轴 0 最大值，即每一列最大值\n",
    "df.max(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f695a536-6b08-4545-9bbe-c8d13a466cec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        2\n",
       "Tensorflow    4\n",
       "Keras         2\n",
       "dtype: int32"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 默认计算轴0最小值\n",
    "df.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "84565f3b-8850-47da-aee7-2e38c1d0b6b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        30.5\n",
       "Tensorflow    41.5\n",
       "Keras         69.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 中位数\n",
    "df.median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "cb677311-8444-4ec5-882d-2f661009d493",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python         799\n",
       "Tensorflow     913\n",
       "Keras         1174\n",
       "dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 求和\n",
    "df.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2e0c8572-31ff-401b-984d-05fa004151cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    70.333333\n",
       "B    78.333333\n",
       "C    48.333333\n",
       "D    40.666667\n",
       "E    51.000000\n",
       "F    58.666667\n",
       "H    70.333333\n",
       "I    44.666667\n",
       "J    35.333333\n",
       "K    34.666667\n",
       "L    37.333333\n",
       "M    24.333333\n",
       "N    16.666667\n",
       "O    51.666667\n",
       "P    64.666667\n",
       "Q    37.666667\n",
       "R    39.333333\n",
       "S    53.666667\n",
       "T    52.666667\n",
       "U    51.666667\n",
       "dtype: float64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 轴1平均值，即每一行的平均值\n",
    "df.mean(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "92c2cc78-bb56-49e8-babf-4666cacf19da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0.2</th>\n",
       "      <td>13.4</td>\n",
       "      <td>17.6</td>\n",
       "      <td>21.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.4</th>\n",
       "      <td>28.0</td>\n",
       "      <td>27.8</td>\n",
       "      <td>64.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.8</th>\n",
       "      <td>66.4</td>\n",
       "      <td>82.8</td>\n",
       "      <td>88.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Python  Tensorflow  Keras\n",
       "0.2    13.4        17.6   21.2\n",
       "0.4    28.0        27.8   64.2\n",
       "0.8    66.4        82.8   88.4"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 分位数\n",
    "df.quantile(q=[0.2, 0.4, 0.8])   # 默认是0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "934e52c6-83a2-4c1c-8f99-eb9cb2952f33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>20.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>20.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>39.950000</td>\n",
       "      <td>45.650000</td>\n",
       "      <td>58.70000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>29.224134</td>\n",
       "      <td>31.618241</td>\n",
       "      <td>33.44296</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>2.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>17.000000</td>\n",
       "      <td>19.750000</td>\n",
       "      <td>33.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>30.500000</td>\n",
       "      <td>41.500000</td>\n",
       "      <td>69.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>56.750000</td>\n",
       "      <td>67.750000</td>\n",
       "      <td>85.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>96.000000</td>\n",
       "      <td>99.000000</td>\n",
       "      <td>98.00000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Python  Tensorflow     Keras\n",
       "count  20.000000   20.000000  20.00000\n",
       "mean   39.950000   45.650000  58.70000\n",
       "std    29.224134   31.618241  33.44296\n",
       "min     2.000000    4.000000   2.00000\n",
       "25%    17.000000   19.750000  33.00000\n",
       "50%    30.500000   41.500000  69.00000\n",
       "75%    56.750000   67.750000  85.00000\n",
       "max    96.000000   99.000000  98.00000"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看数值型列的汇总统计、计数、平均值、标准差、最小值、四分位数、最大值\n",
    "df.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad25b931-e02b-4eeb-b92d-b8880723593c",
   "metadata": {},
   "source": [
    "## 索引标签、位置获取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3459040f-39f2-49a7-b444-35f49d2dbb28",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(5)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算最小值的位置\n",
    "df['Python'].argmin()  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "2117d481-02d6-4864-bb9b-b6f52abaefda",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(14)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算最大值的位置\n",
    "df['Keras'].argmax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "79883523-dd37-4ae2-95ca-739564e6f2a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        L\n",
       "Tensorflow    E\n",
       "Keras         P\n",
       "dtype: object"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取最大值索引标签\n",
    "df.idxmax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "1311b23b-66e2-4f6a-9269-57f32e0874f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        F\n",
       "Tensorflow    J\n",
       "Keras         N\n",
       "dtype: object"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取最小值索引标签\n",
    "df.idxmin()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68018512-fdab-4233-b3ff-5c6fd31c4d05",
   "metadata": {},
   "source": [
    "## 更多统计指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "dec32d38-3234-4f12-9730-3228bbdc71d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python\n",
       "28    2\n",
       "11    2\n",
       "91    1\n",
       "31    1\n",
       "30    1\n",
       "50    1\n",
       "87    1\n",
       "54    1\n",
       "20    1\n",
       "2     1\n",
       "18    1\n",
       "96    1\n",
       "65    1\n",
       "14    1\n",
       "45    1\n",
       "6     1\n",
       "40    1\n",
       "72    1\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 统计元素出现的次数\n",
    "df['Python'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "8a8bdcf3-0a15-4388-bec6-159d3e8e48f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([90, 93, 10, 24, 88, 65, 68, 82, 63,  7, 43,  2,  3, 98, 36, 81, 70,\n",
       "       84, 74], dtype=int32)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 去重\n",
    "df['Keras'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "f921f15a-8478-4ac2-9743-03352857d5e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>28</td>\n",
       "      <td>93</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>119</td>\n",
       "      <td>144</td>\n",
       "      <td>183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>150</td>\n",
       "      <td>165</td>\n",
       "      <td>276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>200</td>\n",
       "      <td>227</td>\n",
       "      <td>286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>230</td>\n",
       "      <td>326</td>\n",
       "      <td>310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>232</td>\n",
       "      <td>412</td>\n",
       "      <td>398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>319</td>\n",
       "      <td>471</td>\n",
       "      <td>463</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>373</td>\n",
       "      <td>483</td>\n",
       "      <td>531</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>393</td>\n",
       "      <td>487</td>\n",
       "      <td>613</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>411</td>\n",
       "      <td>510</td>\n",
       "      <td>676</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>507</td>\n",
       "      <td>519</td>\n",
       "      <td>683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>518</td>\n",
       "      <td>538</td>\n",
       "      <td>726</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>546</td>\n",
       "      <td>558</td>\n",
       "      <td>728</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>611</td>\n",
       "      <td>645</td>\n",
       "      <td>731</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>625</td>\n",
       "      <td>727</td>\n",
       "      <td>829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>670</td>\n",
       "      <td>759</td>\n",
       "      <td>865</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>676</td>\n",
       "      <td>790</td>\n",
       "      <td>946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>716</td>\n",
       "      <td>841</td>\n",
       "      <td>1016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>727</td>\n",
       "      <td>904</td>\n",
       "      <td>1100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>799</td>\n",
       "      <td>913</td>\n",
       "      <td>1174</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      28          93     90\n",
       "B     119         144    183\n",
       "C     150         165    276\n",
       "D     200         227    286\n",
       "E     230         326    310\n",
       "F     232         412    398\n",
       "H     319         471    463\n",
       "I     373         483    531\n",
       "J     393         487    613\n",
       "K     411         510    676\n",
       "L     507         519    683\n",
       "M     518         538    726\n",
       "N     546         558    728\n",
       "O     611         645    731\n",
       "P     625         727    829\n",
       "Q     670         759    865\n",
       "R     676         790    946\n",
       "S     716         841   1016\n",
       "T     727         904   1100\n",
       "U     799         913   1174"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 累加\n",
    "df.cumsum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "700c303b-1a96-42c2-8e66-2538863ccc9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>28</td>\n",
       "      <td>93</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>2548</td>\n",
       "      <td>4743</td>\n",
       "      <td>8370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>78988</td>\n",
       "      <td>99603</td>\n",
       "      <td>778410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>3949400</td>\n",
       "      <td>6175386</td>\n",
       "      <td>7784100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>118482000</td>\n",
       "      <td>611363214</td>\n",
       "      <td>186818400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>236964000</td>\n",
       "      <td>52577236404</td>\n",
       "      <td>16440019200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>20615868000</td>\n",
       "      <td>3102056947836</td>\n",
       "      <td>1068601248000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>1113256872000</td>\n",
       "      <td>37224683374032</td>\n",
       "      <td>72664884864000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>22265137440000</td>\n",
       "      <td>148898733496128</td>\n",
       "      <td>5958520558848000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>400772473920000</td>\n",
       "      <td>3424670870410944</td>\n",
       "      <td>375386795207424000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>38474157496320000</td>\n",
       "      <td>30822037833698496</td>\n",
       "      <td>2627707566451968000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>423215732459520000</td>\n",
       "      <td>585618718840271424</td>\n",
       "      <td>2310960915177314304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>-6596703564842991616</td>\n",
       "      <td>-6734369696904123136</td>\n",
       "      <td>4621921830354628608</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>-4510618019474767872</td>\n",
       "      <td>4405646728046938880</td>\n",
       "      <td>-4580978582645665792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>-7808420051518095360</td>\n",
       "      <td>-7671849774342044160</td>\n",
       "      <td>-6214043330246008832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>-890764917832810496</td>\n",
       "      <td>-5691519820721242112</td>\n",
       "      <td>-2344631004341698560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>-5344589506996862976</td>\n",
       "      <td>8030326294737010688</td>\n",
       "      <td>-5447670614582067200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>7577348604640100352</td>\n",
       "      <td>3718271409977409536</td>\n",
       "      <td>6044682527155879936</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>-8882885717506654208</td>\n",
       "      <td>-5556574129647370240</td>\n",
       "      <td>-8755501782773530624</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>6068270919355203584</td>\n",
       "      <td>5331065054302322688</td>\n",
       "      <td>-2271089345406959616</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Python           Tensorflow                Keras\n",
       "A                   28                   93                   90\n",
       "B                 2548                 4743                 8370\n",
       "C                78988                99603               778410\n",
       "D              3949400              6175386              7784100\n",
       "E            118482000            611363214            186818400\n",
       "F            236964000          52577236404          16440019200\n",
       "H          20615868000        3102056947836        1068601248000\n",
       "I        1113256872000       37224683374032       72664884864000\n",
       "J       22265137440000      148898733496128     5958520558848000\n",
       "K      400772473920000     3424670870410944   375386795207424000\n",
       "L    38474157496320000    30822037833698496  2627707566451968000\n",
       "M   423215732459520000   585618718840271424  2310960915177314304\n",
       "N -6596703564842991616 -6734369696904123136  4621921830354628608\n",
       "O -4510618019474767872  4405646728046938880 -4580978582645665792\n",
       "P -7808420051518095360 -7671849774342044160 -6214043330246008832\n",
       "Q  -890764917832810496 -5691519820721242112 -2344631004341698560\n",
       "R -5344589506996862976  8030326294737010688 -5447670614582067200\n",
       "S  7577348604640100352  3718271409977409536  6044682527155879936\n",
       "T -8882885717506654208 -5556574129647370240 -8755501782773530624\n",
       "U  6068270919355203584  5331065054302322688 -2271089345406959616"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 累乘\n",
    "df.cumprod()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "53e2fc66-c297-40ee-a96f-d5c8096e39e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        29.224134\n",
       "Tensorflow    31.618241\n",
       "Keras         33.442960\n",
       "dtype: float64"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 标准差\n",
    "df.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "73388efd-bb3b-4737-b56b-583b824b81b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python         854.050000\n",
       "Tensorflow     999.713158\n",
       "Keras         1118.431579\n",
       "dtype: float64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方差\n",
    "df.var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "8023fa2d-0fcb-42c8-8b6b-3c3bb9a58789",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>28</td>\n",
       "      <td>93</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>28</td>\n",
       "      <td>51</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>28</td>\n",
       "      <td>21</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>28</td>\n",
       "      <td>21</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>28</td>\n",
       "      <td>21</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>2</td>\n",
       "      <td>21</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>2</td>\n",
       "      <td>21</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      28          93     90\n",
       "B      28          51     90\n",
       "C      28          21     90\n",
       "D      28          21     10\n",
       "E      28          21     10\n",
       "F       2          21     10\n",
       "H       2          21     10\n",
       "I       2          12     10\n",
       "J       2           4     10\n",
       "K       2           4     10\n",
       "L       2           4      7\n",
       "M       2           4      7\n",
       "N       2           4      2\n",
       "O       2           4      2\n",
       "P       2           4      2\n",
       "Q       2           4      2\n",
       "R       2           4      2\n",
       "S       2           4      2\n",
       "T       2           4      2\n",
       "U       2           4      2"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 累计最小值\n",
    "df.cummin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "5c974cb8-6b0e-418d-9d22-011ebe014c27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>28</td>\n",
       "      <td>93</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>91</td>\n",
       "      <td>93</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>91</td>\n",
       "      <td>93</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>91</td>\n",
       "      <td>93</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>96</td>\n",
       "      <td>99</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      28          93     90\n",
       "B      91          93     93\n",
       "C      91          93     93\n",
       "D      91          93     93\n",
       "E      91          99     93\n",
       "F      91          99     93\n",
       "H      91          99     93\n",
       "I      91          99     93\n",
       "J      91          99     93\n",
       "K      91          99     93\n",
       "L      96          99     93\n",
       "M      96          99     93\n",
       "N      96          99     93\n",
       "O      96          99     93\n",
       "P      96          99     98\n",
       "Q      96          99     98\n",
       "R      96          99     98\n",
       "S      96          99     98\n",
       "T      96          99     98\n",
       "U      96          99     98"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 累计最大值\n",
    "df.cummax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "d394f480-81f8-4744-8fda-872836bfde13",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>63.0</td>\n",
       "      <td>-42.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>-60.0</td>\n",
       "      <td>-30.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>19.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>-83.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>-20.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>14.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-28.0</td>\n",
       "      <td>-13.0</td>\n",
       "      <td>64.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>85.0</td>\n",
       "      <td>-27.0</td>\n",
       "      <td>-23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>-33.0</td>\n",
       "      <td>-47.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>-34.0</td>\n",
       "      <td>-8.0</td>\n",
       "      <td>14.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>-2.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>-19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>78.0</td>\n",
       "      <td>-14.0</td>\n",
       "      <td>-56.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>-85.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>17.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-41.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>37.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>-51.0</td>\n",
       "      <td>-5.0</td>\n",
       "      <td>95.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>31.0</td>\n",
       "      <td>-50.0</td>\n",
       "      <td>-62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>-39.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>34.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>-11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>-29.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>14.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>61.0</td>\n",
       "      <td>-54.0</td>\n",
       "      <td>-10.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     NaN         NaN    NaN\n",
       "B    63.0       -42.0    3.0\n",
       "C   -60.0       -30.0    0.0\n",
       "D    19.0        41.0  -83.0\n",
       "E   -20.0        37.0   14.0\n",
       "F   -28.0       -13.0   64.0\n",
       "H    85.0       -27.0  -23.0\n",
       "I   -33.0       -47.0    3.0\n",
       "J   -34.0        -8.0   14.0\n",
       "K    -2.0        19.0  -19.0\n",
       "L    78.0       -14.0  -56.0\n",
       "M   -85.0        10.0   36.0\n",
       "N    17.0         1.0  -41.0\n",
       "O    37.0        67.0    1.0\n",
       "P   -51.0        -5.0   95.0\n",
       "Q    31.0       -50.0  -62.0\n",
       "R   -39.0        -1.0   45.0\n",
       "S    34.0        20.0  -11.0\n",
       "T   -29.0        12.0   14.0\n",
       "U    61.0       -54.0  -10.0"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算差分\n",
    "df.diff()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "4d327041-de0c-45d5-b7c0-037334aff70a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>2.250000</td>\n",
       "      <td>-0.451613</td>\n",
       "      <td>0.033333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>-0.659341</td>\n",
       "      <td>-0.588235</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>0.612903</td>\n",
       "      <td>1.952381</td>\n",
       "      <td>-0.892473</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>-0.400000</td>\n",
       "      <td>0.596774</td>\n",
       "      <td>1.400000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-0.933333</td>\n",
       "      <td>-0.131313</td>\n",
       "      <td>2.666667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>42.500000</td>\n",
       "      <td>-0.313953</td>\n",
       "      <td>-0.261364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>-0.379310</td>\n",
       "      <td>-0.796610</td>\n",
       "      <td>0.046154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>-0.629630</td>\n",
       "      <td>-0.666667</td>\n",
       "      <td>0.205882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>-0.100000</td>\n",
       "      <td>4.750000</td>\n",
       "      <td>-0.231707</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>4.333333</td>\n",
       "      <td>-0.608696</td>\n",
       "      <td>-0.888889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>-0.885417</td>\n",
       "      <td>1.111111</td>\n",
       "      <td>5.142857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>1.545455</td>\n",
       "      <td>0.052632</td>\n",
       "      <td>-0.953488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>1.321429</td>\n",
       "      <td>3.350000</td>\n",
       "      <td>0.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>-0.784615</td>\n",
       "      <td>-0.057471</td>\n",
       "      <td>31.666667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>2.214286</td>\n",
       "      <td>-0.609756</td>\n",
       "      <td>-0.632653</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>-0.866667</td>\n",
       "      <td>-0.031250</td>\n",
       "      <td>1.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>5.666667</td>\n",
       "      <td>0.645161</td>\n",
       "      <td>-0.135802</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>-0.725000</td>\n",
       "      <td>0.235294</td>\n",
       "      <td>0.200000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>5.545455</td>\n",
       "      <td>-0.857143</td>\n",
       "      <td>-0.119048</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Python  Tensorflow      Keras\n",
       "A        NaN         NaN        NaN\n",
       "B   2.250000   -0.451613   0.033333\n",
       "C  -0.659341   -0.588235   0.000000\n",
       "D   0.612903    1.952381  -0.892473\n",
       "E  -0.400000    0.596774   1.400000\n",
       "F  -0.933333   -0.131313   2.666667\n",
       "H  42.500000   -0.313953  -0.261364\n",
       "I  -0.379310   -0.796610   0.046154\n",
       "J  -0.629630   -0.666667   0.205882\n",
       "K  -0.100000    4.750000  -0.231707\n",
       "L   4.333333   -0.608696  -0.888889\n",
       "M  -0.885417    1.111111   5.142857\n",
       "N   1.545455    0.052632  -0.953488\n",
       "O   1.321429    3.350000   0.500000\n",
       "P  -0.784615   -0.057471  31.666667\n",
       "Q   2.214286   -0.609756  -0.632653\n",
       "R  -0.866667   -0.031250   1.250000\n",
       "S   5.666667    0.645161  -0.135802\n",
       "T  -0.725000    0.235294   0.200000\n",
       "U   5.545455   -0.857143  -0.119048"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算百分比变化\n",
    "df.pct_change()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e40cbf4-8c1d-430f-9b8b-b56052560527",
   "metadata": {},
   "source": [
    "## 高级统计指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "c4609027-8e46-4595-96ec-03b185da0446",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Python</th>\n",
       "      <td>854.050000</td>\n",
       "      <td>-137.807895</td>\n",
       "      <td>-295.384211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>-137.807895</td>\n",
       "      <td>999.713158</td>\n",
       "      <td>45.942105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>-295.384211</td>\n",
       "      <td>45.942105</td>\n",
       "      <td>1118.431579</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Python  Tensorflow        Keras\n",
       "Python      854.050000 -137.807895  -295.384211\n",
       "Tensorflow -137.807895  999.713158    45.942105\n",
       "Keras      -295.384211   45.942105  1118.431579"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 两两属性间的协方差\n",
    "df.cov()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "6468264e-61b4-4f2a-82de-017b5a53174d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(-295.3842105263159)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# python和Keras的协方差\n",
    "df['Python'].cov(df['Keras'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "f5350811-d792-4fe9-905b-5a696af285dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Python</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.149140</td>\n",
       "      <td>-0.302232</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>-0.149140</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.043448</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>-0.302232</td>\n",
       "      <td>0.043448</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Python  Tensorflow     Keras\n",
       "Python      1.000000   -0.149140 -0.302232\n",
       "Tensorflow -0.149140    1.000000  0.043448\n",
       "Keras      -0.302232    0.043448  1.000000"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 两两属性之间的相关性系数\n",
    "df.corr()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "256c862d-0ee1-424e-82aa-b9b8bce3668b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python       -0.149140\n",
       "Tensorflow    1.000000\n",
       "Keras         0.043448\n",
       "dtype: float64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 单一属性相关性系数\n",
    "df.corrwith(df['Tensorflow'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a454a4d-b923-4df9-b7bc-dd02730fabec",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
